<?php


namespace app\index\controller;

use app\BaseController;
use app\model\FriendshipLink;
use think\App;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\facade\Db;
use think\facade\Env;
use think\facade\View;

class Base extends BaseController
{
    protected $prefix;
    protected $uid;
    protected $end_point;
    protected $tpl;
    protected $links;
    protected $url;

    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->url = config('site.domain');
        $d = '/pc/';
        if ($this->request->isMobile()) {
            $d = '/m/';
            $this->url = config('site.mobile_domain');
        }
        $this->uid = session('xwx_user_id');
        $this->prefix = Env::get('database.prefix');
        $this->end_point = config('seo.book_end_point');
        $tpl_root = './template/' . config('site.tpl') . $d;
        $controller = strtolower($this->request->controller());
        $action = strtolower($this->request->action());
        $this->tpl = $tpl_root . $controller . '/' . $action . '.html';
        $this->links = cache('friendshipLink');
        if (!$this->links) {
            $this->links = FriendshipLink::select();
            cache('friendshipLink', $this->links, null, 'redis');
        }

        View::assign([
            'url' => $this->url,
            'site_name' => config('site.site_name'),
            'book_ctrl' => BOOKCTRL,
            'chapter_ctrl' => CHAPTERCTRL,
            'booklist_act' => BOOKLISTACT,
            'search_ctrl' => SEARCHCTRL,
            'rank_ctrl' => RANKCTRL,
            'update_act' => UPDATEACT,
            'author_ctrl' => AUTHORCTRL,
            'end_point' => config('seo.book_end_point'),
            'xwx_user_id' => session('xwx_user_id'),
            'xwx_user' => session('xwx_user'),
            'xwx_nick_name' => session('xwx_nick_name'),
            'xwx_user_mobile' => session('xwx_user_mobile'),
            'links' => $this->links
        ]);
    }
}